import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';
import { ISysPrompt, ISysPromptView, ISysPromptVm } from '/@/views/_admin/sysprompt/api/interface';
import { IResult } from '/@/types/common';

interface ISysPromptApi {
	search(data: object): Promise<AxiosResponse<ISysPromptView[]>>;

	get(id: string | number): Promise<AxiosResponse<ISysPromptVm>>;

	add(data: ISysPromptVm): Promise<AxiosResponse<ISysPrompt>>;

	edit(data: ISysPromptVm): Promise<AxiosResponse<ISysPrompt>>;

	batchEdit(data: object): Promise<AxiosResponse>;

	delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;

	export(data: object): Promise<void>;

	exportById(ids: (string | number)[]): Promise<void>;

	import(data: object): Promise<AxiosResponse<number>>;

	approve(data: object, tag: string): Promise<AxiosResponse<any, any>>;
}

function SysPromptApi(): ISysPromptApi {
	return {
		async search(data: object): Promise<AxiosResponse<ISysPromptView[]>> {
			return await request({
				url: '/api/SysPrompt/Search',
				method: 'post',
				data,
			});
		},
		async get(id: string | number): Promise<AxiosResponse<ISysPromptVm>> {
			return await request({
				url: `/api/SysPrompt/${id}`,
				method: 'get',
			});
		},
		async add(data: ISysPromptVm): Promise<AxiosResponse<ISysPrompt>> {
			return await request({
				url: '/api/SysPrompt/Add',
				method: 'post',
				data,
			});
		},
		async edit(data: ISysPromptVm): Promise<AxiosResponse<ISysPrompt>> {
			return await request({
				url: '/api/SysPrompt/Edit',
				method: 'put',
				data,
			});
		},
		async batchEdit(data: object): Promise<AxiosResponse> {
			return await request({
				url: '/api/SysPrompt/batchEdit',
				method: 'post',
				data,
			});
		},
		async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
			return await request({
				url: '/api/SysPrompt/BatchDelete',
				method: 'post',
				data: ids,
			});
		},
		async export(data: object): Promise<void> {
			const response = await request<any, Blob>({
				responseType: 'blob',
				url: '/api/SysPrompt/ExportExcel',
				method: 'post',
				data,
			});
			other.downloadFile(response);
		},
		async exportById(ids: (string | number)[]): Promise<void> {
			const response = await request<any, Blob>({
				responseType: 'blob',
				url: '/api/SysPrompt/ExportExcelByIds',
				method: 'post',
				data: ids,
			});
			other.downloadFile(response);
		},
		async import(data: object): Promise<AxiosResponse<number>> {
			return await request({
				url: '/api/SysPrompt/Import',
				method: 'post',
				data,
			});
		},
		async approve(data: object, tag: string) {
			return request({
				url: '/api/SysPrompt/approve?tag=' + tag,
				method: 'post',
				data,
			});
		},
	};
}

export { SysPromptApi };
